package cn.ibizlab.assetmanagement.assetapi.rest;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import cn.ibizlab.assetmanagement.assetapi.dto.*;
import cn.ibizlab.assetmanagement.assetapi.mapping.*;
import cn.ibizlab.assetmanagement.core.apply.domain.EAMApply;
import cn.ibizlab.assetmanagement.core.apply.service.IEAMApplyService;
import cn.ibizlab.assetmanagement.core.apply.filter.EAMApplySearchContext;
import cn.ibizlab.assetmanagement.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"维护申请" })
@RestController("AssetApi-eamapply")
@RequestMapping("")
public class EAMApplyResource {

    @Autowired
    public IEAMApplyService eamapplyService;

    @Autowired
    @Lazy
    public EAMApplyMapping eamapplyMapping;

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydto),'iBizAssetManagement-EAMApply-Create')")
    @ApiOperation(value = "新建维护申请", tags = {"维护申请" },  notes = "新建维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamapplies")
    @Transactional
    public ResponseEntity<EAMApplyDTO> create(@RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
		eamapplyService.create(domain);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydtos),'iBizAssetManagement-EAMApply-Create')")
    @ApiOperation(value = "批量新建维护申请", tags = {"维护申请" },  notes = "批量新建维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamapplies/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<EAMApplyDTO> eamapplydtos) {
        eamapplyService.createBatch(eamapplyMapping.toDomain(eamapplydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "eamapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.eamapplyService.get(#eamapply_id),'iBizAssetManagement-EAMApply-Update')")
    @ApiOperation(value = "更新维护申请", tags = {"维护申请" },  notes = "更新维护申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/eamapplies/{eamapply_id}")
    @Transactional
    public ResponseEntity<EAMApplyDTO> update(@PathVariable("eamapply_id") String eamapply_id, @RequestBody EAMApplyDTO eamapplydto) {
		EAMApply domain  = eamapplyMapping.toDomain(eamapplydto);
        domain .setEamapplyid(eamapply_id);
		eamapplyService.update(domain );
		EAMApplyDTO dto = eamapplyMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.eamapplyService.getEamapplyByEntities(this.eamapplyMapping.toDomain(#eamapplydtos)),'iBizAssetManagement-EAMApply-Update')")
    @ApiOperation(value = "批量更新维护申请", tags = {"维护申请" },  notes = "批量更新维护申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/eamapplies/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<EAMApplyDTO> eamapplydtos) {
        eamapplyService.updateBatch(eamapplyMapping.toDomain(eamapplydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.eamapplyService.get(#eamapply_id),'iBizAssetManagement-EAMApply-Remove')")
    @ApiOperation(value = "删除维护申请", tags = {"维护申请" },  notes = "删除维护申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/eamapplies/{eamapply_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("eamapply_id") String eamapply_id) {
         return ResponseEntity.status(HttpStatus.OK).body(eamapplyService.remove(eamapply_id));
    }

    @PreAuthorize("hasPermission(this.eamapplyService.getEamapplyByIds(#ids),'iBizAssetManagement-EAMApply-Remove')")
    @ApiOperation(value = "批量删除维护申请", tags = {"维护申请" },  notes = "批量删除维护申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/eamapplies/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        eamapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.eamapplyMapping.toDomain(returnObject.body),'iBizAssetManagement-EAMApply-Get')")
    @ApiOperation(value = "获取维护申请", tags = {"维护申请" },  notes = "获取维护申请")
	@RequestMapping(method = RequestMethod.GET, value = "/eamapplies/{eamapply_id}")
    public ResponseEntity<EAMApplyDTO> get(@PathVariable("eamapply_id") String eamapply_id) {
        EAMApply domain = eamapplyService.get(eamapply_id);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取维护申请草稿", tags = {"维护申请" },  notes = "获取维护申请草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/eamapplies/getdraft")
    public ResponseEntity<EAMApplyDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(eamapplyMapping.toDto(eamapplyService.getDraft(new EAMApply())));
    }

    @ApiOperation(value = "检查维护申请", tags = {"维护申请" },  notes = "检查维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamapplies/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody EAMApplyDTO eamapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(eamapplyService.checkKey(eamapplyMapping.toDomain(eamapplydto)));
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydto),'iBizAssetManagement-EAMApply-Save')")
    @ApiOperation(value = "保存维护申请", tags = {"维护申请" },  notes = "保存维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamapplies/save")
    public ResponseEntity<Boolean> save(@RequestBody EAMApplyDTO eamapplydto) {
        return ResponseEntity.status(HttpStatus.OK).body(eamapplyService.save(eamapplyMapping.toDomain(eamapplydto)));
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydtos),'iBizAssetManagement-EAMApply-Save')")
    @ApiOperation(value = "批量保存维护申请", tags = {"维护申请" },  notes = "批量保存维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamapplies/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<EAMApplyDTO> eamapplydtos) {
        eamapplyService.saveBatch(eamapplyMapping.toDomain(eamapplydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizAssetManagement-EAMApply-searchDefault-all') and hasPermission(#context,'iBizAssetManagement-EAMApply-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"维护申请" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/eamapplies/fetchdefault")
	public ResponseEntity<List<EAMApplyDTO>> fetchDefault(EAMApplySearchContext context) {
        Page<EAMApply> domains = eamapplyService.searchDefault(context) ;
        List<EAMApplyDTO> list = eamapplyMapping.toDto(domains.getContent());
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizAssetManagement-EAMApply-searchDefault-all') and hasPermission(#context,'iBizAssetManagement-EAMApply-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"维护申请" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/eamapplies/searchdefault")
	public ResponseEntity<Page<EAMApplyDTO>> searchDefault(@RequestBody EAMApplySearchContext context) {
        Page<EAMApply> domains = eamapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(eamapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydto),'iBizAssetManagement-EAMApply-Create')")
    @ApiOperation(value = "根据资产建立维护申请", tags = {"维护申请" },  notes = "根据资产建立维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamassets/{eamasset_id}/eamapplies")
    @Transactional
    public ResponseEntity<EAMApplyDTO> createByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
        domain.setAssetid(eamasset_id);
		eamapplyService.create(domain);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydtos),'iBizAssetManagement-EAMApply-Create')")
    @ApiOperation(value = "根据资产批量建立维护申请", tags = {"维护申请" },  notes = "根据资产批量建立维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamassets/{eamasset_id}/eamapplies/batch")
    public ResponseEntity<Boolean> createBatchByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody List<EAMApplyDTO> eamapplydtos) {
        List<EAMApply> domainlist=eamapplyMapping.toDomain(eamapplydtos);
        for(EAMApply domain:domainlist){
            domain.setAssetid(eamasset_id);
        }
        eamapplyService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "eamapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.eamapplyService.get(#eamapply_id),'iBizAssetManagement-EAMApply-Update')")
    @ApiOperation(value = "根据资产更新维护申请", tags = {"维护申请" },  notes = "根据资产更新维护申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/eamassets/{eamasset_id}/eamapplies/{eamapply_id}")
    @Transactional
    public ResponseEntity<EAMApplyDTO> updateByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @PathVariable("eamapply_id") String eamapply_id, @RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
        domain.setAssetid(eamasset_id);
        domain.setEamapplyid(eamapply_id);
		eamapplyService.update(domain);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.eamapplyService.getEamapplyByEntities(this.eamapplyMapping.toDomain(#eamapplydtos)),'iBizAssetManagement-EAMApply-Update')")
    @ApiOperation(value = "根据资产批量更新维护申请", tags = {"维护申请" },  notes = "根据资产批量更新维护申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/eamassets/{eamasset_id}/eamapplies/batch")
    public ResponseEntity<Boolean> updateBatchByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody List<EAMApplyDTO> eamapplydtos) {
        List<EAMApply> domainlist=eamapplyMapping.toDomain(eamapplydtos);
        for(EAMApply domain:domainlist){
            domain.setAssetid(eamasset_id);
        }
        eamapplyService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.eamapplyService.get(#eamapply_id),'iBizAssetManagement-EAMApply-Remove')")
    @ApiOperation(value = "根据资产删除维护申请", tags = {"维护申请" },  notes = "根据资产删除维护申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/eamassets/{eamasset_id}/eamapplies/{eamapply_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @PathVariable("eamapply_id") String eamapply_id) {
		return ResponseEntity.status(HttpStatus.OK).body(eamapplyService.remove(eamapply_id));
    }

    @PreAuthorize("hasPermission(this.eamapplyService.getEamapplyByIds(#ids),'iBizAssetManagement-EAMApply-Remove')")
    @ApiOperation(value = "根据资产批量删除维护申请", tags = {"维护申请" },  notes = "根据资产批量删除维护申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/eamassets/{eamasset_id}/eamapplies/batch")
    public ResponseEntity<Boolean> removeBatchByEAMAsset(@RequestBody List<String> ids) {
        eamapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.eamapplyMapping.toDomain(returnObject.body),'iBizAssetManagement-EAMApply-Get')")
    @ApiOperation(value = "根据资产获取维护申请", tags = {"维护申请" },  notes = "根据资产获取维护申请")
	@RequestMapping(method = RequestMethod.GET, value = "/eamassets/{eamasset_id}/eamapplies/{eamapply_id}")
    public ResponseEntity<EAMApplyDTO> getByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @PathVariable("eamapply_id") String eamapply_id) {
        EAMApply domain = eamapplyService.get(eamapply_id);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据资产获取维护申请草稿", tags = {"维护申请" },  notes = "根据资产获取维护申请草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/eamassets/{eamasset_id}/eamapplies/getdraft")
    public ResponseEntity<EAMApplyDTO> getDraftByEAMAsset(@PathVariable("eamasset_id") String eamasset_id) {
        EAMApply domain = new EAMApply();
        domain.setAssetid(eamasset_id);
        return ResponseEntity.status(HttpStatus.OK).body(eamapplyMapping.toDto(eamapplyService.getDraft(domain)));
    }

    @ApiOperation(value = "根据资产检查维护申请", tags = {"维护申请" },  notes = "根据资产检查维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamassets/{eamasset_id}/eamapplies/checkkey")
    public ResponseEntity<Boolean> checkKeyByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplyDTO eamapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(eamapplyService.checkKey(eamapplyMapping.toDomain(eamapplydto)));
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydto),'iBizAssetManagement-EAMApply-Save')")
    @ApiOperation(value = "根据资产保存维护申请", tags = {"维护申请" },  notes = "根据资产保存维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamassets/{eamasset_id}/eamapplies/save")
    public ResponseEntity<Boolean> saveByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
        domain.setAssetid(eamasset_id);
        return ResponseEntity.status(HttpStatus.OK).body(eamapplyService.save(domain));
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydtos),'iBizAssetManagement-EAMApply-Save')")
    @ApiOperation(value = "根据资产批量保存维护申请", tags = {"维护申请" },  notes = "根据资产批量保存维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamassets/{eamasset_id}/eamapplies/savebatch")
    public ResponseEntity<Boolean> saveBatchByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody List<EAMApplyDTO> eamapplydtos) {
        List<EAMApply> domainlist=eamapplyMapping.toDomain(eamapplydtos);
        for(EAMApply domain:domainlist){
             domain.setAssetid(eamasset_id);
        }
        eamapplyService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizAssetManagement-EAMApply-searchDefault-all') and hasPermission(#context,'iBizAssetManagement-EAMApply-Get')")
	@ApiOperation(value = "根据资产获取DEFAULT", tags = {"维护申请" } ,notes = "根据资产获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/eamassets/{eamasset_id}/eamapplies/fetchdefault")
	public ResponseEntity<List<EAMApplyDTO>> fetchEAMApplyDefaultByEAMAsset(@PathVariable("eamasset_id") String eamasset_id,EAMApplySearchContext context) {
        context.setN_assetid_eq(eamasset_id);
        Page<EAMApply> domains = eamapplyService.searchDefault(context) ;
        List<EAMApplyDTO> list = eamapplyMapping.toDto(domains.getContent());
	    return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizAssetManagement-EAMApply-searchDefault-all') and hasPermission(#context,'iBizAssetManagement-EAMApply-Get')")
	@ApiOperation(value = "根据资产查询DEFAULT", tags = {"维护申请" } ,notes = "根据资产查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/eamassets/{eamasset_id}/eamapplies/searchdefault")
	public ResponseEntity<Page<EAMApplyDTO>> searchEAMApplyDefaultByEAMAsset(@PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplySearchContext context) {
        context.setN_assetid_eq(eamasset_id);
        Page<EAMApply> domains = eamapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(eamapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydto),'iBizAssetManagement-EAMApply-Create')")
    @ApiOperation(value = "根据功能位置资产建立维护申请", tags = {"维护申请" },  notes = "根据功能位置资产建立维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies")
    @Transactional
    public ResponseEntity<EAMApplyDTO> createByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
        domain.setAssetid(eamasset_id);
		eamapplyService.create(domain);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydtos),'iBizAssetManagement-EAMApply-Create')")
    @ApiOperation(value = "根据功能位置资产批量建立维护申请", tags = {"维护申请" },  notes = "根据功能位置资产批量建立维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/batch")
    public ResponseEntity<Boolean> createBatchByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody List<EAMApplyDTO> eamapplydtos) {
        List<EAMApply> domainlist=eamapplyMapping.toDomain(eamapplydtos);
        for(EAMApply domain:domainlist){
            domain.setAssetid(eamasset_id);
        }
        eamapplyService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "eamapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.eamapplyService.get(#eamapply_id),'iBizAssetManagement-EAMApply-Update')")
    @ApiOperation(value = "根据功能位置资产更新维护申请", tags = {"维护申请" },  notes = "根据功能位置资产更新维护申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/{eamapply_id}")
    @Transactional
    public ResponseEntity<EAMApplyDTO> updateByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @PathVariable("eamapply_id") String eamapply_id, @RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
        domain.setAssetid(eamasset_id);
        domain.setEamapplyid(eamapply_id);
		eamapplyService.update(domain);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.eamapplyService.getEamapplyByEntities(this.eamapplyMapping.toDomain(#eamapplydtos)),'iBizAssetManagement-EAMApply-Update')")
    @ApiOperation(value = "根据功能位置资产批量更新维护申请", tags = {"维护申请" },  notes = "根据功能位置资产批量更新维护申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/batch")
    public ResponseEntity<Boolean> updateBatchByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody List<EAMApplyDTO> eamapplydtos) {
        List<EAMApply> domainlist=eamapplyMapping.toDomain(eamapplydtos);
        for(EAMApply domain:domainlist){
            domain.setAssetid(eamasset_id);
        }
        eamapplyService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.eamapplyService.get(#eamapply_id),'iBizAssetManagement-EAMApply-Remove')")
    @ApiOperation(value = "根据功能位置资产删除维护申请", tags = {"维护申请" },  notes = "根据功能位置资产删除维护申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/{eamapply_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @PathVariable("eamapply_id") String eamapply_id) {
		return ResponseEntity.status(HttpStatus.OK).body(eamapplyService.remove(eamapply_id));
    }

    @PreAuthorize("hasPermission(this.eamapplyService.getEamapplyByIds(#ids),'iBizAssetManagement-EAMApply-Remove')")
    @ApiOperation(value = "根据功能位置资产批量删除维护申请", tags = {"维护申请" },  notes = "根据功能位置资产批量删除维护申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/batch")
    public ResponseEntity<Boolean> removeBatchByEAMLocationEAMAsset(@RequestBody List<String> ids) {
        eamapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.eamapplyMapping.toDomain(returnObject.body),'iBizAssetManagement-EAMApply-Get')")
    @ApiOperation(value = "根据功能位置资产获取维护申请", tags = {"维护申请" },  notes = "根据功能位置资产获取维护申请")
	@RequestMapping(method = RequestMethod.GET, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/{eamapply_id}")
    public ResponseEntity<EAMApplyDTO> getByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @PathVariable("eamapply_id") String eamapply_id) {
        EAMApply domain = eamapplyService.get(eamapply_id);
        EAMApplyDTO dto = eamapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据功能位置资产获取维护申请草稿", tags = {"维护申请" },  notes = "根据功能位置资产获取维护申请草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/getdraft")
    public ResponseEntity<EAMApplyDTO> getDraftByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id) {
        EAMApply domain = new EAMApply();
        domain.setAssetid(eamasset_id);
        return ResponseEntity.status(HttpStatus.OK).body(eamapplyMapping.toDto(eamapplyService.getDraft(domain)));
    }

    @ApiOperation(value = "根据功能位置资产检查维护申请", tags = {"维护申请" },  notes = "根据功能位置资产检查维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/checkkey")
    public ResponseEntity<Boolean> checkKeyByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplyDTO eamapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(eamapplyService.checkKey(eamapplyMapping.toDomain(eamapplydto)));
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydto),'iBizAssetManagement-EAMApply-Save')")
    @ApiOperation(value = "根据功能位置资产保存维护申请", tags = {"维护申请" },  notes = "根据功能位置资产保存维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/save")
    public ResponseEntity<Boolean> saveByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplyDTO eamapplydto) {
        EAMApply domain = eamapplyMapping.toDomain(eamapplydto);
        domain.setAssetid(eamasset_id);
        return ResponseEntity.status(HttpStatus.OK).body(eamapplyService.save(domain));
    }

    @PreAuthorize("hasPermission(this.eamapplyMapping.toDomain(#eamapplydtos),'iBizAssetManagement-EAMApply-Save')")
    @ApiOperation(value = "根据功能位置资产批量保存维护申请", tags = {"维护申请" },  notes = "根据功能位置资产批量保存维护申请")
	@RequestMapping(method = RequestMethod.POST, value = "/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/savebatch")
    public ResponseEntity<Boolean> saveBatchByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody List<EAMApplyDTO> eamapplydtos) {
        List<EAMApply> domainlist=eamapplyMapping.toDomain(eamapplydtos);
        for(EAMApply domain:domainlist){
             domain.setAssetid(eamasset_id);
        }
        eamapplyService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizAssetManagement-EAMApply-searchDefault-all') and hasPermission(#context,'iBizAssetManagement-EAMApply-Get')")
	@ApiOperation(value = "根据功能位置资产获取DEFAULT", tags = {"维护申请" } ,notes = "根据功能位置资产获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/fetchdefault")
	public ResponseEntity<List<EAMApplyDTO>> fetchEAMApplyDefaultByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id,EAMApplySearchContext context) {
        context.setN_assetid_eq(eamasset_id);
        Page<EAMApply> domains = eamapplyService.searchDefault(context) ;
        List<EAMApplyDTO> list = eamapplyMapping.toDto(domains.getContent());
	    return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizAssetManagement-EAMApply-searchDefault-all') and hasPermission(#context,'iBizAssetManagement-EAMApply-Get')")
	@ApiOperation(value = "根据功能位置资产查询DEFAULT", tags = {"维护申请" } ,notes = "根据功能位置资产查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/eamlocations/{eamlocation_id}/eamassets/{eamasset_id}/eamapplies/searchdefault")
	public ResponseEntity<Page<EAMApplyDTO>> searchEAMApplyDefaultByEAMLocationEAMAsset(@PathVariable("eamlocation_id") String eamlocation_id, @PathVariable("eamasset_id") String eamasset_id, @RequestBody EAMApplySearchContext context) {
        context.setN_assetid_eq(eamasset_id);
        Page<EAMApply> domains = eamapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(eamapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

